import yhq from '../config/yhq';
export default {
    initIconFont() {
        const domModule = weex.requireModule('dom');
        domModule.addRule('fontFace', {
            fontFamily: 'iconfont',
            'src': "url('bmlocal://iconfont/nbiot/iconfont.ttf')"
        });
    },
    params(key) {
        let bundleUrl = weex.config.bundleUrl;
        let reg = new RegExp('[?|&]' + key + '=([^&]+)');
        let match = bundleUrl.match(reg)
        return match && match[1]
    },
    toParams(obj) {
        let param = "";
        for (const name in obj) {
            if (typeof obj[name] !== 'function') {
                param += "&" + name + "=" + encodeURI(obj[name])
            }
        }
        return param.substring(1)
    },
    /**
     * 版本比较
     * @param latestVersion
     * @returns {boolean}
     */
    compareVersion(latestVersion) {
        let appVersion = weex.config.env.appVersion;
        if (latestVersion === appVersion) {
            return false;
        }
        let lvArr = latestVersion.split('.');
        let appVerArr = appVersion.split('.');
        let needUpdate = false;
        lvArr.forEach((lv, i) => {
            if (!needUpdate) {
                let av = appVerArr[i];
                if (lv - av > 0) {
                    needUpdate = true;
                }
            }
        });
        return needUpdate;
    }
}
